'use strict';

angular.module('myApp.view1', ['ngRoute'])

.config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/view1', {
    templateUrl: 'view1/view1.html',
    controller: 'View1Ctrl'
  });
}])

.controller('View1Ctrl', [function() {

       var name = "蒋红岩";
       var selection = "a";
       var count = 25;
       var cost = 1.51;
       var found = true;
       var object = null;
       var flag = undefined;

       var color1 = "red";
       var color2 = color1;
       console.log(color1);
       console.log(color2);
       color1 = "blue";
       console.log(color1);
       console.log(color2);
       console.log(typeof 10);
       var  name = "蒋红岩";
       console.log(name.toLocaleLowerCase());
       console.log(name.charAt(0));
       console.log(name.substring(2,1));
        var count = 10;
        console.log(count.toFixed(2));
        console.log(count.toString(16));
         var flag = true;
         console.log(flag.toString());
        var  obj1 = new Object();
        var  obj2 = obj1;
        obj1.myCP ="Aer!"
        console.log(obj2.myCP);


var  book ={
    name:"javascript精髓",
    year:20150831
}
console.log(book.name);
var colors = ["1","2","3","4","5"];
        console.log(colors[3]);
        function reflect(value) {
            console.log(value);
            return value;

        }
      var array =[];
        array.push(876543);
        array["push"](123);
        console.log(array)
        var itemss =[];
        console.log( itemss instanceof Array);
        console.log( Array.isArray(itemss));

        var sayHi=  function(){
            console.log("hi!");
        };
        sayHi();
        var sayHi2 =sayHi;
         sayHi2();
        //function sum(){
        //    var re = 0,
        //    i= 0,
        //    len = arguments.length;
        //    while(i<len){
        //        re += arguments[i];
        //    }
        //    return re;
        //}
        //console.log( sum(1,2,3,4,5));
        function sayMessage(message){
            if(arguments.length ===0)
            {
                message ="DE MES"
            }
            console.log(message);
        }
          sayMessage("Hello!");
        //var person ={
        //    name:"jiang",
        //    sayName:function(){
        //        console.log(person.name);
        //    }
        //}
        //person.sayName();


        function sayNameForAll(){
            console.log(this.name);
        }

        var  p1 ={
            name:"xiao",
            sayName:sayNameForAll
        };
        var p2= {
            name:"niao",
            sayName:sayNameForAll
        };


        p1.sayName();
        p2.sayName();
        var P1 ={
            name:"NI"
        }
        var P2 ={
            name:"GR"
        }
        function SayN(label){
            console.log(label+":"+this.name);

        }
      SayN.call(P1,"xiao");
      SayN.call(P2,"P2");
        SayN.apply(P1,["XIA"]);
        SayN.apply(P2,["PW"])
        var SayN1=SayN.bind(p1);
        SayN1("PPP");
        var SayN2 =SayN.bind(P2,"P2");
        SayN2;
        P2.sayName =SayN1;
        P2.sayName("yyy");
     console.log("name" in P1);
     console.log(P1.hasOwnProperty("name"));
        delete P2.name;
      console.log(P2.name);

        var per1 = {
            _name :"xixi",
            get name(){
                console.log("Reading name");
                return this._name;
            },
            set name (value){
                console.log("Setting name to%s",value);
                this._name =value;
            }
        };
        console.log(per1.name);
        per1.name ="Geng";
        console.log(per1.name);

        var son ={
            name:"xiaomao"
        }
        Object.defineProperty(son,"name",{
            enumerable :false
        });
        console.log("name" in son);
        console.log(son.propertyIsEnumerable("name"));
        var ties = Object.keys(son);
        console.log(ties.length);

        Object.defineProperty(son,"name",{
            configurable :false
        });
       var a ={};
        Object.defineProperties(a,{
            _name:{
                value:"xiaoqing",
                enumerable:true,
                configurable:true,
                writable:true
            },
            name:{
                get:function(){
                    console.log("R name");
                    return this._name;
                },
                set:function(value){
                    console.log("S name to%s",value);
                    this._name = value;
                },
                enumerable:true,
                configurable:true
            }

        });
       /* var b = {
            name:"unu",
            age:"13"
        };
        //禁止扩展
        Object.preventExtensions(b);
        console.log(object.isExtensible(b));
        //对象封印
        object.seal(b);
        console.log(object.isSealed(b));
        //对象冻结
        object.freeze(b);
       console.log( object.isFrozen(b));

*/
       /* function Person(name){
            this.name =name;
            this.sys=function(){
                console.log(this.name);
            };
            }
        var pp= new Person("HAO");
        var jj= new Person("DOUHAO");
        console.log(pp.name);
        console.log(jj.name);
        pp.sys();
        jj.sys();
         var object ={};
        console.log(object.toString());
        object.toString =function(){
            return "[object Custom]";
        };
        console.log(object.toString());*/
         function Person (name){
             this.name = name;
         }
        //Person.prototype.sayname =function(){
        //    console.log(this.name);
        //}
        Person.prototype = {
            constructor :Person,
         sayname:function(){
             console.log(this.nam);
         },
         toString:function(){
           return "[Person "+this.name+"]"
         }
        };
        var name1= new Person("YI");
        var name2 = new  Person("JIAO");
        name1.sayname();
        console.log("sayHi" in name1);
        Person.prototype.sayHi = function(){
            console.log("Hi");
        }
        name1.sayHi();
        name2.sayHi();
        Array.prototype.sum =function(){
            return this.reduce(function(previous,current){
                return previous+current;
            });
        };
        var num =[1,2,3,4,5,6];
        var result = num.sum();
        console.log(result);
         var now = new Date();
        var earlier = new  Date(2015,9,1);
        console.log(now>earlier);
        /*var per1={
            name:"xiao",
            sya:function(){
                console.log(this.name);
            }
        };
        var per2= object.create(per1,{
            name:{
                configurable:true,
                enumerable:true,
                value:"Greg",
                writable:true
            }
        });
        console.log(per1.isPrototypeOf(per2));
        console.log(per2.hasOwnProperty("sya"));*/
      function Rectangle(length,width){
          this.length = length;
          this.width = width;
      }
        Rectangle.prototype.getArea =function(){
            return this.length*this.width;
        }
        Rectangle.prototype.toString = function(){
           return "[Rectangle"+ this.length+"x"+this.width+"]" ;
        };
       //function Square(size){
       //    this.length=size;
       //    this.width =size;
       //}

        //Square.prototype = new Rectangle();
        ////设置一个自有属性
        //Square.prototype.constructor =Square;

        function Square(size){
            Rectangle.call(this,size,size);
        }
         Square.prototype =Object.create(Rectangle.prototype,{
             constructor:{
                 configurable:true,
                 enumerable:true,
                 value:Square,
                 writable:true
             }
         });
        Square.prototype.toString = function(){
           return"[Square"+this.length+"x"+this.width+"]" ;
        };
        var rect =new Rectangle(5,10);
        var square =new Square(6);
        console.log(rect.getArea());
        console.log(square.getArea());
        console.log( rect.toString());
        console.log( square.toString());
        console.log(rect instanceof  Rectangle);
        console.log(rect instanceof  Object);
        console.log(square instanceof  Square);
        console.log(square instanceof  Rectangle);
        console.log(square instanceof  Object);
        console.log(square.length);
        console.log(square.width);
        function REC(L,W){
            this.length =L;
            this.width =W;
        }
        REC.prototype.getARC = function(){
            return "[Rectangle"+ this.length+"x"+this.width+"]" ;
        };
        function SQ(size){
            REC.call(this,size,size);
        }
        SQ.prototype =Object.create(REC.prototype,{
           constructor:{
               configurable:true,
               enumerable:true,
               value:SQ,
               writable:true
           }

        });
        //SQ.prototype.toString()通过call()方法调用REC.prototype.toString()
        SQ.prototype.toSource= function(){
            var text = REC.prototype.toString.call(this);
            //ＳＱ替换ＲＥＣ
            return text.replace("REC","SQ");
        }

        var PERSON=(function(){
            var age =26;
            return{
                name:"xiaoqing",
                getAge:function(){
                    return age;
                },
                getOlder:function(){
                    age++;
                }
            };
        }());
        console.log(PERSON.name);
        console.log(PERSON.getAge());
        PERSON.age =100;
        console.log(PERSON.getAge());
        PERSON.getOlder();
        console.log(PERSON.getAge());
        //暴露模块模式
        var abc=(function(){
            var age =18;
            function getAge(){
                return age;
            }
            function growOlder(){
                age++;
            }
            return{
                name:"tingting",
                getAge:getAge,
                growOlder:growOlder
            };
        }());
        var yyy =(function(){
            var age =21;
            function iNN(name){
                this.name =name;
            }
            iNN.prototype.getAge =function (){
                return age;
            };
            iNN.prototype.growOlder =function(){
                age++;
            };
            return iNN;
        }());
         var Y1= new yyy("uie");
         var Y2= new yyy("iuy");
        console.log(Y1.name);
        console.log(Y1.getAge());
        console.log(Y2.name);
        console.log(Y2.getAge());
        Y1.growOlder();
        console.log(Y1.getAge());
        console.log(Y2.getAge());
    }]);
